package de.reminder.client;

import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.ui.*;

import de.reminder.client.event.InitializedEvent;
import de.reminder.client.event.InitializedEventHandler;
import de.reminder.client.section.AllReminderSection;
import de.reminder.client.section.SettingsSection;
import de.reminder.client.section.SingleReminderSection;
import de.reminder.client.widgets.*;
import de.reminder.shared.model.FacebookUser;

public class Mainframe extends Composite implements InitializedEventHandler{
	private AbsolutePanel wrapper;
	private HTML frame_top;
	private HTML frame_bottom;
	private Header header;
	private VerticalPanel content;
	private PhotoClip photoclip;
	private SingleReminderSection singleReminderSection;
	private AllReminderSection allReminderSection;
	private SettingsSection settingsSection;
	
	private PushButton loginButton;
	
	public Mainframe(){
		frame_top = new HTML();
		frame_top.setPixelSize(860, 128);
		frame_top.getElement().setId("MainframeTop");
		
		MySimpleReminder.eventBus.addHandler(InitializedEvent.TYPE, this);
		
		header = new Header();
		
		frame_bottom = new HTML();
		frame_bottom.setPixelSize(860, 28);
		frame_bottom.getElement().setId("MainframeBottom");
		
		content = new VerticalPanel();
		content.getElement().setId("MainframeContent");
		content.setWidth("860px");
		
		loginButton = new PushButton(new Image("images/mainframe/loginButton.png"));
		loginButton.getElement().setClassName("");
		loginButton.addClickHandler(new ClickHandler() {
			
			@Override
			public void onClick(ClickEvent event) {
				MySimpleReminder.getInstance().getAccessToken();
			}
		});
		content.add(loginButton);
		
		wrapper = new AbsolutePanel();
		wrapper.add(frame_top);
		wrapper.add(header);
		wrapper.add(content);
		wrapper.add(frame_bottom);
		
		photoclip = new PhotoClip(120);
		photoclip.setUnknownUser();
		wrapper.add(photoclip,650,50);
		
		initWidget(wrapper);
		
		wrapper.getElement().setId("Mainframe");

	}
	
	private class Header extends Composite{
		private VerticalPanel wrapper;
		private Label heading;
		private Label subheading;
		
		public Header(){
			wrapper = new VerticalPanel();
			wrapper.getElement().setId("MainframeContent");
			wrapper.setWidth("860px");
			heading = new Label("My Simple Reminder");
			heading.setStyleName("Handwritten");
			heading.addStyleName("H1");
			
			subheading = new Label("Please login with your facebook account!");
			subheading.setStyleName("Handwritten");
			subheading.addStyleName("H2");
			
			wrapper.add(heading);
			wrapper.add(subheading);
			
			initWidget(wrapper);			
		}
	}

	@Override
	public void onInitialized(InitializedEvent event) {
		singleReminderSection = new SingleReminderSection(this);
		allReminderSection = new AllReminderSection();
		settingsSection = new SettingsSection();
		
		photoclip.removeUnknownUser();
		photoclip.addUser(MySimpleReminder.currentUser);
		
		content.remove(loginButton);
		
		content.add(singleReminderSection);
		content.setCellVerticalAlignment(singleReminderSection, HasAlignment.ALIGN_MIDDLE);
		content.add(allReminderSection);
		content.add(settingsSection);
	}
}
